package star.cloud.asme.base.file.fileInfo;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import star.cloud.asme.base.dto.Result;
import star.cloud.asme.base.mybatis.IBaseController;

import java.util.List;

@RestController
@RequestMapping("/base/file/fileInfo")
@RequiredArgsConstructor
@Slf4j
public class FileInfoController implements IBaseController<FileInfo> {

    private final FileInfoService fileInfoService;

    @Override
    public Result<FileInfo> getOneByCondition(String columnName, Object columnValue) {
        return fileInfoService.getOneByCondition(columnName, columnValue);
    }

    @PostMapping("/uploadOne")
    public FileInfo upload(FileInfo fileInfo, MultipartFile file) {
        return fileInfoService.uploadOneFile(fileInfo, file);
    }

    @PostMapping("/appendOne")
    public FileInfo appendOne(FileInfo fileInfo, MultipartFile file) {
        return fileInfoService.appendOneFile(fileInfo, file);
    }

    @Override
    public Result<?> physicalDeleteById(Long id) {
        return fileInfoService.physicalDeleteById(id);
    }

    @DeleteMapping("/physicalDeleteByUid/{uid}")
    public Result<?> physicalDeleteByUid(@PathVariable("uid") Long uid) {
        return fileInfoService.physicalDeleteByUid(uid);
    }

    @DeleteMapping("/physicalDeleteByKeyWord/{keyWord}")
    public Result<?> physicalDeleteByKeyWord(@PathVariable("keyWord") String keyWord) {
        return fileInfoService.physicalDeleteByKeyWord(keyWord);
    }

    @Override
    public Result<?> logicalDeleteById(Long id) {
        return fileInfoService.logicalDeleteById(id);
    }


    @GetMapping("/getList/keyWord/{keyWord}")
    public Result<List<FileInfo>> getListByKeyword(@PathVariable(name = "keyWord") String keyWord) {
        return fileInfoService.getFileInfoListByKeyword(keyWord);
    }

    @GetMapping("/getOne/keyWord/{keyWord}")
    public Result<FileInfo> getOneByKeyWord(@PathVariable(name = "keyWord") String keyWord) {
        return fileInfoService.getOneByKeyword(keyWord);
    }
}